﻿using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
using System.IO;
using System;
using Microsoft.VisualStudio.Shell;
using FunctionPoint.Common;
using FunctionPoint.UIManagers;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Editor;

namespace FunctionPoint.Services
{
    #region Adornment Factory
    /// <summary>
    /// Establishes an <see cref="IAdornmentLayer"/> to place the adornment on and exports the <see cref="IWpfTextViewCreationListener"/>
    /// that instantiates the adornment on the event of a <see cref="IWpfTextView"/>'s creation
    /// </summary>
    [Export(typeof(IWpfTextViewCreationListener))]
    [ContentType("text")]
    [TextViewRole(PredefinedTextViewRoles.Document)]
    internal sealed class FunctionPointLocationAdornmentFactory : IWpfTextViewCreationListener
    {
        /// <summary>
        /// Defines the adornment layer for the scarlet adornment. This layer is ordered 
        /// after the selection layer in the Z-order
        /// </summary>
        [Export(typeof(AdornmentLayerDefinition))]
        [Name(FunctionPoint.Common.Constants.VIEWPORT_ADORNMENTLAYERNAME)]
        [Order(After = PredefinedAdornmentLayers.Selection)]
        [TextViewRole(PredefinedTextViewRoles.Document)]
        public AdornmentLayerDefinition editorAdornmentLayer = null;

        [Import(typeof(SVsServiceProvider))]
        private IServiceProvider VsServiceProvider { get; set; }

        [Import(typeof(IVsEditorAdaptersFactoryService))]
        IVsEditorAdaptersFactoryService editorFactory { get; set; }

        /// <summary>
        /// Instantiates a FunctionPoint.Viewport.Adornment manager when a textView is created.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> upon which the adornment should be placed</param>
        public void TextViewCreated(IWpfTextView textView)
        {


        }

        private WpfTextViewAdornmentManager GetOrCreateManager(IWpfTextView textView) {
            return textView.Properties.GetOrCreateSingletonProperty<WpfTextViewAdornmentManager>(() =>
                new WpfTextViewAdornmentManager(textView, ServiceProvider.GlobalProvider));

        }

    }
    #endregion //Adornment Factory
}
